clear
use "Turning Discontent into Votes Candidates data"


egen ethnic_id = group( ethnic)
gen ethnic_year_id=(ethnic_id*10000)+ elect_year
tab ethnic_year_id
xtset ethnic_year_id

global control "incumbent ethnicpop_pct ln_pop n_ethnicparty_cand cand_female"


	//Table 2
xtreg pct $control, fe 


xtreg pct ethnonat dist_gini $control if n_ethnicparty_cand>1, fe
outreg2 using Table2.doc, replace dec(3) 
xtreg pct c.ethnonat##c.dist_gini $control,  fe
//outreg2 using Table2.doc, dec(3) append
quietly margins, at(dist_gini=(.2(.1).5) ethnonat=(5.25,8.8)) 
marginsplot

xtreg pct  territory dist_gini $control if n_ethnicparty_cand>1, fe
outreg2 using Table2.doc, dec(3) append
xtreg pct c.territory##c.dist_gini $control if n_ethnicparty_cand>1, fe
outreg2 using Table2.doc, dec(3) append
quietly margins, at(dist_gini=(.2(.1).5) territory=(4.1,10)) 
marginsplot


xtreg pct culture dist_gini $control if n_ethnicparty_cand>1, fe
outreg2 using Table2.doc, dec(3) append
xtreg pct c.culture##c.dist_gini $control if n_ethnicparty_cand>1, fe
outreg2 using Table2.doc, dec(3) append
quietly margins, at(dist_gini=(.2(.1).5) culture=(7.4,10)) 
marginsplot, recast(line) recastci(rline) scheme(s1mono)



//Graphs (Fix)

xtreg pct c.ethnonat##c.dist_gini $control,  fe
quietly margins, dydx(ethnonat) at(dist_gini=(.2(.01).5))
marginsplot, recast(line) recastci(rline) scheme(s1mono) title("Ethnonationalism") xtitle("District Inequality") ysc(range(-.2 .2) titlegap(1)) ylabel(-.2(.1).2) ytitle("Marginal effect on Vote Share with 95% CIs") nodraw saving(ethn, replace)
xtreg pct c.territory##c.dist_gini $control, 
quietly margins, dydx(territory) at(dist_gini=(.2(.01).5)) 
marginsplot, recast(line) recastci(rline) scheme(s1mono) title("Cultural Autonomy") xtitle("District Inequality") ysc(range(-.2 .2) titlegap(1)) ylabel(-.2(.1).2) ytitle("Marginal Effect on Vote Share with 95% CIs") nodraw saving(terr, replace) 
xtreg pct c.culture##c.dist_gini $control, 
quietly margins, dydx(culture) at(dist_gini=(.2(.01).5))
marginsplot, recast(line) recastci(rline) scheme(s1mono) title("Territorrial Autonomy") xtitle("District Inequality") ysc(range(-.2 .2) titlegap(2)) ylabel(-.2(.1).2) ytitle("Marginal effect on Vote Share with 95% CIs") nodraw saving(cult, replace)

gr combine ethn.gph terr.gph cult.gph, col(3) iscale(.8) ycommon scheme(s1mono)
























